﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Manager;
namespace HealthSystem
{
    public partial class Result : BasePage
    {
        ResultManager manager = new ResultManager();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                districtname.OnClientTriggerClick = Window1.GetSaveStateReference(districtname.ClientID,districtid.ClientID)
                   + Window1.GetShowReference("sysAdmin/dischoose.aspx","地区选择");
               
                //BindGrid();
                chooseyear.DataSource = HealthSystem.ReportPage.ReportCofig.GetReportYear();
                chooseyear.DataTextField = "YearName";
                chooseyear.DataValueField = "YearCode";
                chooseyear.DataBind();

                if (CustomerProfile.RoleId == 1003 || CustomerProfile.RoleId == 1012)
                {
                    districtid.Text = CustomerProfile.AdminUser.DistrictCode;
                    districtname.Text = CustomerProfile.AdminUser.hW_District.Name;
                    districtname.Readonly = true;
                }
            }
        }
        public string GetYear()
        {
            return chooseyear.SelectedValue;
        }
        private void BindGrid()
        {
            string district = districtid.Text;
            string yearcode = this.chooseyear.SelectedValue;
            string name = searchstring.Text.Trim();
            string fild = contion.SelectedValue;
            string schoolcode = Schoolcode.Text;
            int count = 0;
            System.Data.DataTable dt = null;
            if (CustomerProfile.RoleId == 1000 || CustomerProfile.RoleId == 1001)
            {
                if (string.IsNullOrEmpty(district))
                    dt = manager.Search(Gird1.PageIndex, Gird1.PageSize, out count, yearcode, name, fild);
                    //dt = manager.NoPageSearch(out count, yearcode, name, fild);
                else
                    dt = manager.Search(Gird1.PageIndex, Gird1.PageSize, out count, yearcode, name, fild, district, schoolcode, ismerge.Checked);
                    //dt = manager.NoPageSearch(out count, yearcode, name, fild, district, schoolcode, ismerge.Checked);
            }
            else
            {
                if (string.IsNullOrEmpty(district))
                    district = CustomerProfile.DistrictId;
                //dt = manager.Search(Gird1.PageIndex, Gird1.PageSize, out count, yearcode, name, fild, district, schoolcode, ismerge.Checked);
                dt = manager.NoPageSearch(out count, yearcode, name, fild, district, schoolcode, ismerge.Checked);
            }
            //Gird1.IsDatabasePaging = false;
            Gird1.RecordCount = count;
            Gird1.DataSource = dt;
            Gird1.DataBind();
        }
        protected void Search_Clik(object sender, EventArgs e)
        {
            Gird1.PageIndex = 0;
            BindGrid();
        }
        protected void Window1_Close(object sender, EventArgs e)
        {
        }
        protected void PageIndexChange(object sender, ExtAspNet.GridPageEventArgs e)
        {
            Gird1.PageIndex = e.NewPageIndex;
            BindGrid();
        }
        protected void Grid1_DoubleClick(object sender, ExtAspNet.GridRowClickEventArgs e)
        {
        }
        protected void school_click(object sender,EventArgs e)
        {
            string district = districtid.Text;
            if (string.IsNullOrEmpty(district))
            {
                ExtAspNet.Alert.Show("请先选择区域");
                return;
            }

            ExtAspNet.PageContext.RegisterStartupScript(Window2.GetSaveStateReference(Schoolcode.ClientID, chooseSchool.ClientID)
                  + Window2.GetShowReference("ChooseSchool.aspx?districtid=" + district,districtname.Text+"学校"));
        }
        protected void rowcommand(object sender, ExtAspNet.GridCommandEventArgs e)
        {
            if (e.CommandName == "download")
            {
                string student=Gird1.Rows[e.RowIndex].DataKeys[0] as string;
                string url = "resultinfo.aspx?tjnd=" + this.chooseyear.SelectedValue + "&studentid=" + student;
                Response.Redirect("<script>window.open('"+url+"')</script>");
            }
        }
    }
}